home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / PCX_LIB.ARJ / WR_DEMO.C < prev    next >
C/C++ Source or Header  |  1991-04-03  |  7KB  |  210 lines

  1. /*
  2.  *************************************************************************
  3.  *
  4.  *  WR_DEMO.C - PCX_LIB PCX Image File Write Demonstration Program
  5.  *
  6.  *  Version:    1.00B
  7.  *
  8.  *  History:    91/02/14 - Created
  9.  *              91/04/01 - Release 1.00A
  10.  *              91/04/06 - Release 1.00B
  11.  *
  12.  *  Compiler:   Microsoft C V6.0
  13.  *
  14.  *  Author:     Ian Ashdown, P.Eng.
  15.  *              byHeart Software
  16.  *              620 Ballantree Road
  17.  *              West Vancouver, B.C.
  18.  *              Canada V7S 1W3
  19.  *              Tel. (604) 922-6148
  20.  *              Fax. (604) 987-7621
  21.  *
  22.  *  Copyright:  Public Domain
  23.  *
  24.  *************************************************************************
  25.  */
  26.  
  27. /*      INCLUDE FILES                                                   */
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <conio.h>
  32. #include <graph.h>
  33. #include "pcx_ext.h"
  34.  
  35. /*      FORWARD REFERENCES                                              */
  36.  
  37. /*      GLOBALS                                                         */
  38.  
  39. static char *use_msg[] =        /* Program usage message                */
  40. {
  41.   "  Synopsis:  This public domain program displays a Paintbrush (R) PCX",
  42.   "-format\n             image file, then captures the image directly fr",
  43.   "om the display\n             and writes it to the file PCX_DEMO.PCX.",
  44.   "\n\n  Usage:     WR_DEMO filename video_mode\n\n             where \"",
  45.   "filename\" is the name of the PCX-format image file to be\n          ",
  46.   "   written and \"video_mode\" is an MS-DOS video mode.  Valid values",
  47.   "\n             are:\n\n                4   - 320 x 200 4-color CGA\n ",
  48.   "               5   - 320 x 200 4-color CGA (color burst off)\n       ",
  49.   "         6   - 640 x 200 2-color CGA\n               13   - 320 x 200",
  50.   " 16-color EGA/VGA\n               14   - 640 x 200 16-color EGA/VGA\n",
  51.   "               15   - 640 x 350 2-color EGA/VGA\n               16   ",
  52.   "- 640 x 350 16-color EGA/VGA\n               17   - 640 x 480 2-color",
  53.   " VGA\n               18   - 640 x 480 16-color VGA\n               19",
  54.   "   - 320 x 200 256-color VGA\n",
  55.   (unsigned char *) NULL
  56. };
  57.  
  58. /*      PUBLIC FUNCTIONS                                                */
  59.  
  60. /*
  61.  *************************************************************************
  62.  *
  63.  *  MAIN - Executive Function
  64.  *
  65.  *  Purpose:    To write a PCX-format image file.
  66.  *
  67.  *  Setup:      int main
  68.  *              (
  69.  *                int argc,
  70.  *                char **argv
  71.  *              )
  72.  *
  73.  *  Where:      argc is the number of command-line arguments.
  74.  *              argv is a pointer to an array of command-line argument
  75.  *                strings.
  76.  *
  77.  *  Return:     0 if successful; otherwise 2.
  78.  *
  79.  *  Note:       Usage is:
  80.  *
  81.  *                WR_DEMO filename video_mode
  82.  *
  83.  *              where:
  84.  *
  85.  *                filename is the name of a PCX-format image file.
  86.  *                video_mode is the MS-DOS video mode.  Valid values are:
  87.  *
  88.  *                    4 -        320 x 200 4-color CGA
  89.  *                    5 -        320 x 200 4-color CGA (color burst off)
  90.  *                    6 -        640 x 200 2-color CGA
  91.  *                   13 -        320 x 200 16-color EGA/VGA
  92.  *                   14 -        640 x 200 16-color EGA/VGA
  93.  *                   15 -        640 x 350 2-color EGA/VGA
  94.  *                   16 -        640 x 350 16-color EGA/VGA
  95.  *                   17 -        640 x 480 2-color VGA
  96.  *                   18 -        640 x 480 16-color VGA
  97.  *                   19 -        320 x 200 256-color VGA
  98.  *
  99.  *************************************************************************
  100.  */
  101.  
  102. int main
  103. (
  104.   int argc,
  105.   char **argv
  106. )
  107. {
  108.   int i;                /* Scratch counter                              */
  109.   int vmode;            /* Video mode                                   */
  110.   BOOL status = FALSE;  /* Return status                                */
  111.   PCX_VSB *vsbp;        /* Video services data save buffer ptr          */
  112.  
  113.   vsbp = (PCX_VSB *) NULL;      /* Initialize video services buffer ptr */
  114.  
  115.   /* Display program title                                              */
  116.  
  117.   puts("\nWR_DEMO - PCX Image File Write Demonstration Program\n");
  118.  
  119.   if (argc == 3)        /* Check for filename and video mode parameters */
  120.   {
  121.     vmode = atoi(argv[2]);      /* Get the video mode                   */
  122.  
  123.     /* Validate the video mode (must be valid MS-DOS graphics mode)     */
  124.  
  125.     if ((vmode >= 4 && vmode <= 6) || (vmode >= 13 && vmode <= 19))
  126.       status = TRUE;
  127.   }
  128.  
  129.   if (status == TRUE)
  130.   {
  131.     if (_setvideomode(vmode) == 0)      /* Set the video mode           */
  132.     {
  133.       /* Report error                                                   */
  134.  
  135.       fprintf(stderr,
  136.           "ERROR: could not set display adapter to mode %d.\n", vmode);
  137.  
  138.       return (2);
  139.     }
  140.  
  141.     if (vmode >= 13 && vmode <= 18)     /* EGA-compatible video mode ?  */
  142.     {
  143.       if (pcx_isvga() == TRUE)  /* Is a VGA display present ?           */
  144.       {
  145.         /* An EGA display adapter is present - instantiate a Dynamic    */
  146.         /* Save Area buffer to capture the color palette settings each  */
  147.         /* time the palette is updated                                  */
  148.  
  149.         status = pcx_init_dsa(&vsbp);
  150.       }
  151.     }
  152.  
  153.     if (status == TRUE)
  154.     {
  155.       /* Read and display the file (assume video page zero)             */
  156.  
  157.       if ((status = pcx_read(argv[1], vmode, 0)) == TRUE)
  158.       {
  159.         /* Capture the entire screen as a PCX-format file               */
  160.  
  161.         status = pcx_write("PCX_DEMO.PCX", vmode, 0, 640, 480);
  162.  
  163.         (void) _setvideomode(_DEFAULTMODE);     /* Reset the video mode */
  164.  
  165.         if (status == FALSE)
  166.         {
  167.           /* Report error                                               */
  168.  
  169.           fprintf(stderr,
  170.               "\nWR_DEMO - PCX Image File Write Demonstration");
  171.           fprintf(stderr,
  172.               " Program\n\nERROR: Could not write file %s.\n", argv[1]);
  173.         }
  174.       }
  175.       else
  176.       {
  177.         (void) _setvideomode(_DEFAULTMODE);     /* Reset the video mode */
  178.  
  179.         /* Report error                                                 */
  180.  
  181.         fprintf(stderr, "\nWR_DEMO - PCX Image File Write Demonstration");
  182.         fprintf(stderr, " Program\n\nERROR: Could not read file %s.\n",
  183.             argv[1]);
  184.       }
  185.  
  186.       /* Free the Dynamic Save Area (if necessary)                      */
  187.  
  188.       if (vsbp != (PCX_VSB *) NULL)
  189.         pcx_free_dsa(vsbp);
  190.     }
  191.     else
  192.     {
  193.       (void) _setvideomode(_DEFAULTMODE);       /* Reset the video mode */
  194.  
  195.       fputs("ERROR: out of memory.\n", stderr);         /* Report error */
  196.     }
  197.   }
  198.   else          /* Display usage information                            */
  199.   {
  200.     while (use_msg[i] != (unsigned char *) NULL)
  201.       fputs(use_msg[i++], stderr);
  202.   }
  203.  
  204.   if (status == TRUE)
  205.     return (0);
  206.   else
  207.     return (2);
  208. }
  209.  
  210.